﻿using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using ATSIDAL;
using ATSModel;

namespace ATSDAL
{
    public class Role : BaseRepository<TRoleInfo>, IRole
    {
        private const string PARM_USER_ID = "@UserID";
        private const string PARM_USER_NAME = "@UserName";

        public IList<TRoleInfo> LoadEntities()
        {
            return null;
        }

        /// <summary>
        /// Get an individual category based on a provided id
        /// </summary>
        /// <param name="categoryId">Category id</param>
        /// <returns>Details about the Category</returns>
        public TRoleInfo LoadEntity<T1>(T1 UserID)
        {
            SqlParameter parm = GetParameter();
            //Bind the parameter
            parm.Value = UserID;
            return ExcuteSqlToGetEntity("Role_selectbyName", parm);
        }

        //验证用户名 密码 （标签打印软件对接）
        public TRoleInfo GetForUser(string UserID)
        {
            SqlParameter parm = GetParameter(PARM_USER_ID);
            parm.Value = UserID;
            return ExcuteSqlToGetEntity("Role_selectbyName", parm);
        }


        //-------------------------------------重写超类基础操作---------------------------------------------------------
       
        public override TRoleInfo GetEntityRecord(SqlDataReader rdr)
        {
            TRoleInfo pro = new TRoleInfo
            {
                ID =int.Parse(rdr.GetValue(0).ToString()),
                UserID = int.Parse(rdr.GetValue(1).ToString()),
                User = rdr.GetValue(2).ToString(), 
                Password = rdr.GetValue(3).ToString(),
                Power = rdr.GetValue(4).ToString(),
                Remark = rdr.GetValue(5).ToString() 
            };
            return pro;
        }


        public override TRoleInfo GetEntityRecord()
        {
            TRoleInfo pro = new TRoleInfo();
            return pro;
        }

        public override string GetInsertsp()
        {
            return "Roler_Insert";
        }

        public static SqlParameter GetParameter(string parmname)
        {
            SqlParameter Parm = new SqlParameter(PARM_USER_ID, SqlDbType.NChar, 10);
            return Parm;
        }

        public override SqlParameter[] GetParameters()
        {
            SqlParameter[] parms = null;
            parms = new SqlParameter[]
                {
					new SqlParameter(PARM_USER_ID, SqlDbType.NChar, 10),
                    //new SqlParameter(PARM_USER_NAME, SqlDbType.NChar, 10)
                };
            return parms;
        }

        public override void SetParameters(TRoleInfo role, params SqlParameter[] Parms)
        {
            Parms[0].Value = role.UserID;
            ////Parms[1].Value = role.UserName;
        }


 
    }
}
